/**
 * Project Name:scapp-web
 * File Name:EmployeeController.java
 * Package Name:com.sc.controller
 * Date:2018年7月3日上午10:41:21
 * Copyright (c) 2018, bluemobi All Rights Reserved.
 */

package com.sc.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sc.app.restful.DataResult;
import com.sc.pojo.Employee;
import com.sc.service.EmployeeService;

/**
 * Description:   <br/>
 * Date:     2018年7月3日 上午10:41:21 <br/>
 * @author   Qbaba
 * @version
 * @see
 */
@Controller
public class EmployeeController {

    @Autowired
    EmployeeService  employeeService;
    
    
    
    /**
     * Q -start
     * */
    
    static void setContAndHeader(HttpServletResponse response){
        /*if(aus.verification(username, password)>0){*/
        response.setContentType("text/html;charset=utf-8");          
        //设置响应头允许ajax跨域访问   
        response.setHeader("Access-Control-Allow-Origin", "*");
        //星号表示所有的异域请求都可以接受， 
        response.setHeader("Access-Control-Allow-Methods", "GET,POST");  
    }
    
    @ResponseBody
    @RequestMapping(value="doLogin")
    public DataResult<Employee> doLogin(HttpServletResponse response,String eusername,String epassword){
        setContAndHeader(response);
        System.out.println("获取账号："+eusername+"---获取密码："+epassword);
        response.setHeader("Access-Control-Allow-Methods", "GET,POST"); 
        Employee emp=employeeService.selectByUsPwdOutEmInfo(new Employee(eusername, epassword));
        System.out.println("返回的数据："+emp);
        DataResult<Employee> e= new DataResult<Employee>(emp);
        System.out.println("打包后的数据："+e);
        return e;
    }
    
    @RequestMapping("updataEphoneAndEimages")
    @ResponseBody
    public DataResult<Integer> updataEphoneAndEimages(HttpServletResponse response,Integer eid, String ephone, String eimage){
        setContAndHeader(response);
        System.out.println("获取id："+eid+"获取电话："+ephone+"---获取图片："+eimage);
        
        int flag =  employeeService.updateByPrimaryKeySelective(new Employee(eid,ephone,eimage));
        
        return new DataResult<Integer>(flag);
    }
    
    
    
}

